import HttpRequestService from "../services/http-request-service";
import DynamicElementDefinitionConstant from "./dynamic-element-definition-constant";

export default class DynamicElementDataService {
  private static readonly url: string = '/bas/ds/data';

  /**
   * Queries data from api.
   * 
   * Post body param example:
   * {
   *     "auth": {
   *         "prodId": "V003CFF9CFA866A1E0438760007FE88C",
   *         "userId": "eb0edd1fd2a949d29b3b35f2e52b4ee4"
   *     },
   *     "filter": "IDX_ID in :IDX_IDS && VALUE_TYPE == 100803 && PUBLISH_DT >= :PUBLISH_DT",
   *     "filterParams": {
   *         "IDX_IDS": [ // 指标ID集合
   *             120126725,
   *             120013415,
   *             120013414
   *         ],
   *         "PUBLISH_DT": "[2019-10-13]" // 参数为图形组件中传参的查询日期条件即 query 参数配置
   *     },
   *     "ignoreTotal": true,
   *     "objName": "CBD_GENERAL_CHART_INDEX_DATA_CACHE_1"
   * }
   */
  static async queryByObjName(objName: string, filter: string | null, filterParams: Object | null, orders: any[] = []): Promise<any> {
    const response = await HttpRequestService.post(this.url, {
      auth: DynamicElementDefinitionConstant.auth,
      filter: filter,
      filterParams: filterParams,
      ignoreTotal: true,
      objName: objName,
      orders: orders,
    });

    return response.payload;
  }
}